import { Dictionary } from "../../utils/dictionary";
import signEntity from "./signEntity";

/**
 * @Author: 陈瑞鹏
 * @Date:   2023-01-11 16:28:28
 * @Last Modified by:   陈瑞鹏
 * @Last Modified time: 2023-01-11 17:38:23
 */
export default class signCtr {
  private static _ins: signCtr = null;

  public static get ins(): signCtr {
    if (this._ins == null) {
      this._ins = new signCtr();
    }
    return this._ins;
  }

  public signDic: Dictionary<number, signEntity>;

  public signDay: number = 1;

  public isSign: boolean = false; //今天是否已经签到

  initData(data) {
    this.signDic = new Dictionary();
    let signEny: signEntity;
    let date = new Date();
    let yy = date.getFullYear();
    let mm = (date.getMonth() + 1) < 10 ? "0" + (date.getMonth() + 1) : (date.getMonth() + 1);
    let dd = date.getDate();
    let now = yy + "-" + mm + "-" + dd;
    let signDay = this.signDay = data.signDay;
    if (now == data.updateTime) {
      this.isSign = true;
      if (this.signDay == 1) {
        this.signDay = 7;
        signDay = 8;
      } else {
        this.signDay -= 1;
      }
    } else {
      this.isSign = false;
    }

    data.signArr.forEach(element => {
      signEny = new signEntity();
      signEny.initData(element);
      signEny.isSign = signEny.day < signDay;
      this.signDic.set(signEny.day, signEny);
    });
    console.log(now);
    console.log(data.updateTime);
    console.log(data.signArr);
  }
}